/*******************************************************************
 *   > File Name: buzzer.c
 *   > Author: fly
 *   > Mail: 1358326274@qq.com
 *   > Create Time: 2019年10月30日 星期三 16时44分07秒
 ******************************************************************/
#define GPD0CON     0xE02000A0
#define GPD0DAT     0xE02000A4

#define rGPD0CON    (*(volatile unsigned int *)GPD0CON)
#define rGPD0DAT    (*(volatile unsigned int *)GPD0DAT)

extern void buzzer_init(void);
extern void buzzer_on(void);
extern void buzzer_off(void);
extern void delay(void);
extern void delay_s(unsigned int t);

int main(int argc, char* argv[])
{
	buzzer_init();
	
	while(1)
	{
		buzzer_on();
        delay();
        buzzer_off();
        delay();
	}
	
    return 0;
}

void buzzer_init(void)
{
    rGPD0CON = 0x00000100;
}

void buzzer_on(void)
{
    rGPD0DAT = (1<<2);
}

void buzzer_off(void)
{
    rGPD0DAT = (0<<2);
}

void delay(void)
{
    volatile unsigned int i = 900000;		// volatile 让编译器不要优化，这样才能真正的减
    while (i--);							// 才能消耗时间，实现delay
}

void delay_s(unsigned int t)
{
    while(--t);
}
